package app.modules.security.enums;

import app.modules.security.constant.SecurityMsgConstants;
import jasmine.framework.i18n.I18nKeyAndArgs;

import javax.annotation.Nullable;

/**
 * @author mh.z
 */
public enum AccessPolicyEnum implements I18nKeyAndArgs {
    ANONYMOUS("ANONYMOUS", SecurityMsgConstants.ACCESS_POLICY_ANONYMOUS),
    AUTHENTICATED("AUTHENTICATED", SecurityMsgConstants.ACCESS_POLICY_AUTHENTICATED),
    GRANTED("GRANTED", SecurityMsgConstants.ACCESS_POLICY_GRANTED);

    private String code;
    private String i18nKey;

    AccessPolicyEnum(String code, String i18nKey) {
        this.code = code;
        this.i18nKey = i18nKey;
    }

    public String getCode() {
        return code;
    }

    @Override
    public String getI18nKey() {
        return i18nKey;
    }

    public boolean codeEquals(@Nullable String code) {
        return this.code.equals(code);
    }

    public static AccessPolicyEnum parseCode(@Nullable String code) {
        if (code == null) {
            return null;
        }

        return valueOf(code);
    }

}
